package com.lagou.rpc.provider.utils;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class Curator {


    @Bean
    public CuratorFramework getClient() {
        //不使用fluent编程风格
        RetryPolicy exponentialBackoffRetry = new ExponentialBackoffRetry(1000, 3);
        // 使用fluent编程风格
        CuratorFramework client = CuratorFrameworkFactory.builder()
                .connectString("192.168.184.134:2181")
                .sessionTimeoutMs(50000)
                .connectionTimeoutMs(30000)
                .retryPolicy(exponentialBackoffRetry)
                .namespace("base")  // 独立的命名空间 /base
                .build();

        client.start();
        return client;
      /*  System.out.println("create sesion");

    // 创建节点
    String path = "/lg-curator/c1";
    String s = client.create().creatingParentsIfNeeded()
            .withMode(CreateMode.PERSISTENT).forPath(path, "init".getBytes());
        System.out.println("get" + s);*/
    }


}
